import uuid
import time
import random
import base64
import hashlib

class ConversationIdGenerator:
    @staticmethod
    def generate_short_uuid() -> str:
        """生成32字符的UUID（移除连字符）"""
        return str(uuid.uuid4()).replace("-", "")[:32]

    @staticmethod
    def generate_timestamp_random() -> str:
        """时间戳+随机数方案（32字符）"""
        # 13位毫秒时间戳 + 19位随机数
        timestamp = str(int(time.time() * 1000)).zfill(13)
        random_part = str(random.getrandbits(63)).zfill(19)  # 63位随机数≈19位十进制
        return timestamp + random_part

    @staticmethod
    def generate_base62_uuid() -> str:
        """Base62编码的UUID（约22字符）"""
        uuid_bytes = uuid.uuid4().bytes
        # 转换为Base64（URL安全），然后移除填充符
        base64_str = base64.urlsafe_b64encode(uuid_bytes).decode().rstrip("=")
        # 转换为Base62（移除非字母数字字符）
        return "".join(c for c in base64_str if c.isalnum())

    @staticmethod
    def generate_sha256_short() -> str:
        """SHA256摘要方案（32字符）"""
        raw_uuid = str(uuid.uuid4()).encode()
        return hashlib.sha256(raw_uuid).hexdigest()[:32]